using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CatalogSystemProxy;
using System.Xml;

namespace CatalogManager.ProductForms
{
	/// <summary>
	/// Summary description for ProductEditor.
	/// </summary>
	public class ProductEditor : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnBack;
		private System.Windows.Forms.Button btnSaveNBack;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Panel panelPropertiesProd;
		private System.Windows.Forms.Panel panelNavProducts;
		private System.Windows.Forms.TabControl tabControlProducts;
		private System.Windows.Forms.TabPage tabPageProductProperties;
		private System.Windows.Forms.TabPage tabPageProductVariants;
		private System.Windows.Forms.TabPage tabPageAssiagnedCategories;
		private System.Windows.Forms.TabPage tabPageRelationShip;
		private System.Windows.Forms.Button btnVariantNew;
		private System.Windows.Forms.Button btnVariantRemove;
		private System.Windows.Forms.Button btnVariantDone;
		private System.Windows.Forms.Button btnVariantCancel;
		private System.Windows.Forms.Button btnRemoveCategory;
		private System.Windows.Forms.Button btnAddCategory;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.DataGrid dataGridProductProperties;
		private CatalogSystem CSService = null;
		private System.Windows.Forms.ListView listViewVariants;
		private System.Windows.Forms.DataGrid dataGridVariants;
		private System.Windows.Forms.ListView listViewProductCategories;
		private System.Windows.Forms.TreeView treeViewCategories;

		public string catalogName=null;
		public string imagePath = null;
		public bool NewProduct = false;
		public string DefinitionName = null;
		public bool NewVariant = false;
		VariantListView lv = null;
		public DataSet ProductProperties=null;
		public string Action=null;
		private System.Windows.Forms.DataGrid dataGridRelationShip;
		private System.Windows.Forms.Button btnRefresh;
		private System.Windows.Forms.Label lblPrimaryParent;
		private System.Windows.Forms.Button btnEdit;
		private System.Windows.Forms.Button btnNew;
		private System.Windows.Forms.RadioButton rdoUseCategoryPrice;
		private System.Windows.Forms.Button btnClear;
		private System.Windows.Forms.Button btnSet;
		private System.Windows.Forms.TextBox txtPrimaryCategory;
		private System.Windows.Forms.Button btnRelationShipCancel;
		private System.Windows.Forms.Button btnRelationShipRemove;
		private System.Windows.Forms.Button btnRelationShipEdit;
		private System.Windows.Forms.Button btnRelationShipNew;
		private System.Windows.Forms.RadioButton rdoDirectPricing;
		private System.Windows.Forms.TabPage tabPageImage;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.Label lblImage;
		private System.Windows.Forms.ImageList TreeViewimageList;
		public TreeNode treeNodeCat = null;
		
		public ProductEditor()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ProductEditor));
			this.panelPropertiesProd = new System.Windows.Forms.Panel();
			this.tabControlProducts = new System.Windows.Forms.TabControl();
			this.tabPageProductProperties = new System.Windows.Forms.TabPage();
			this.dataGridProductProperties = new System.Windows.Forms.DataGrid();
			this.tabPageProductVariants = new System.Windows.Forms.TabPage();
			this.dataGridVariants = new System.Windows.Forms.DataGrid();
			this.listViewVariants = new System.Windows.Forms.ListView();
			this.btnVariantCancel = new System.Windows.Forms.Button();
			this.btnVariantDone = new System.Windows.Forms.Button();
			this.btnVariantRemove = new System.Windows.Forms.Button();
			this.btnVariantNew = new System.Windows.Forms.Button();
			this.tabPageAssiagnedCategories = new System.Windows.Forms.TabPage();
			this.btnRefresh = new System.Windows.Forms.Button();
			this.rdoDirectPricing = new System.Windows.Forms.RadioButton();
			this.rdoUseCategoryPrice = new System.Windows.Forms.RadioButton();
			this.btnClear = new System.Windows.Forms.Button();
			this.btnSet = new System.Windows.Forms.Button();
			this.txtPrimaryCategory = new System.Windows.Forms.TextBox();
			this.lblPrimaryParent = new System.Windows.Forms.Label();
			this.btnEdit = new System.Windows.Forms.Button();
			this.btnNew = new System.Windows.Forms.Button();
			this.btnAddCategory = new System.Windows.Forms.Button();
			this.btnRemoveCategory = new System.Windows.Forms.Button();
			this.listViewProductCategories = new System.Windows.Forms.ListView();
			this.treeViewCategories = new System.Windows.Forms.TreeView();
			this.TreeViewimageList = new System.Windows.Forms.ImageList(this.components);
			this.tabPageRelationShip = new System.Windows.Forms.TabPage();
			this.dataGridRelationShip = new System.Windows.Forms.DataGrid();
			this.btnRelationShipCancel = new System.Windows.Forms.Button();
			this.btnRelationShipRemove = new System.Windows.Forms.Button();
			this.btnRelationShipEdit = new System.Windows.Forms.Button();
			this.btnRelationShipNew = new System.Windows.Forms.Button();
			this.tabPageImage = new System.Windows.Forms.TabPage();
			this.lblImage = new System.Windows.Forms.Label();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.panelNavProducts = new System.Windows.Forms.Panel();
			this.btnSave = new System.Windows.Forms.Button();
			this.btnSaveNBack = new System.Windows.Forms.Button();
			this.btnBack = new System.Windows.Forms.Button();
			this.panelPropertiesProd.SuspendLayout();
			this.tabControlProducts.SuspendLayout();
			this.tabPageProductProperties.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGridProductProperties)).BeginInit();
			this.tabPageProductVariants.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGridVariants)).BeginInit();
			this.tabPageAssiagnedCategories.SuspendLayout();
			this.tabPageRelationShip.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGridRelationShip)).BeginInit();
			this.tabPageImage.SuspendLayout();
			this.panelNavProducts.SuspendLayout();
			this.SuspendLayout();
			// 
			// panelPropertiesProd
			// 
			this.panelPropertiesProd.Controls.AddRange(new System.Windows.Forms.Control[] {
																							  this.tabControlProducts,
																							  this.panelNavProducts});
			this.panelPropertiesProd.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panelPropertiesProd.Name = "panelPropertiesProd";
			this.panelPropertiesProd.Size = new System.Drawing.Size(678, 356);
			this.panelPropertiesProd.TabIndex = 0;
			// 
			// tabControlProducts
			// 
			this.tabControlProducts.Controls.AddRange(new System.Windows.Forms.Control[] {
																							 this.tabPageProductProperties,
																							 this.tabPageProductVariants,
																							 this.tabPageAssiagnedCategories,
																							 this.tabPageRelationShip,
																							 this.tabPageImage});
			this.tabControlProducts.Name = "tabControlProducts";
			this.tabControlProducts.SelectedIndex = 0;
			this.tabControlProducts.Size = new System.Drawing.Size(680, 320);
			this.tabControlProducts.TabIndex = 0;
			// 
			// tabPageProductProperties
			// 
			this.tabPageProductProperties.Controls.AddRange(new System.Windows.Forms.Control[] {
																								   this.dataGridProductProperties});
			this.tabPageProductProperties.Location = new System.Drawing.Point(4, 22);
			this.tabPageProductProperties.Name = "tabPageProductProperties";
			this.tabPageProductProperties.Size = new System.Drawing.Size(672, 294);
			this.tabPageProductProperties.TabIndex = 0;
			this.tabPageProductProperties.Text = "Product Properties";
			// 
			// dataGridProductProperties
			// 
			this.dataGridProductProperties.CaptionVisible = false;
			this.dataGridProductProperties.DataMember = "";
			this.dataGridProductProperties.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridProductProperties.Location = new System.Drawing.Point(8, 8);
			this.dataGridProductProperties.Name = "dataGridProductProperties";
			this.dataGridProductProperties.Size = new System.Drawing.Size(656, 280);
			this.dataGridProductProperties.TabIndex = 0;
			// 
			// tabPageProductVariants
			// 
			this.tabPageProductVariants.Controls.AddRange(new System.Windows.Forms.Control[] {
																								 this.dataGridVariants,
																								 this.listViewVariants,
																								 this.btnVariantCancel,
																								 this.btnVariantDone,
																								 this.btnVariantRemove,
																								 this.btnVariantNew});
			this.tabPageProductVariants.Location = new System.Drawing.Point(4, 22);
			this.tabPageProductVariants.Name = "tabPageProductVariants";
			this.tabPageProductVariants.Size = new System.Drawing.Size(672, 294);
			this.tabPageProductVariants.TabIndex = 1;
			this.tabPageProductVariants.Text = "Product Variants";
			// 
			// dataGridVariants
			// 
			this.dataGridVariants.DataMember = "";
			this.dataGridVariants.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridVariants.Location = new System.Drawing.Point(8, 144);
			this.dataGridVariants.Name = "dataGridVariants";
			this.dataGridVariants.Size = new System.Drawing.Size(432, 144);
			this.dataGridVariants.TabIndex = 7;
			// 
			// listViewVariants
			// 
			this.listViewVariants.FullRowSelect = true;
			this.listViewVariants.Location = new System.Drawing.Point(8, 8);
			this.listViewVariants.MultiSelect = false;
			this.listViewVariants.Name = "listViewVariants";
			this.listViewVariants.Size = new System.Drawing.Size(432, 128);
			this.listViewVariants.TabIndex = 6;
			this.listViewVariants.Click += new System.EventHandler(this.listViewVariants_Click);
			// 
			// btnVariantCancel
			// 
			this.btnVariantCancel.Location = new System.Drawing.Point(448, 184);
			this.btnVariantCancel.Name = "btnVariantCancel";
			this.btnVariantCancel.TabIndex = 5;
			this.btnVariantCancel.Text = "Cancel";
			this.btnVariantCancel.Click += new System.EventHandler(this.btnVariantCancel_Click);
			// 
			// btnVariantDone
			// 
			this.btnVariantDone.Location = new System.Drawing.Point(448, 152);
			this.btnVariantDone.Name = "btnVariantDone";
			this.btnVariantDone.TabIndex = 4;
			this.btnVariantDone.Text = "Done";
			this.btnVariantDone.Click += new System.EventHandler(this.btnVariantDone_Click);
			// 
			// btnVariantRemove
			// 
			this.btnVariantRemove.Location = new System.Drawing.Point(448, 48);
			this.btnVariantRemove.Name = "btnVariantRemove";
			this.btnVariantRemove.TabIndex = 3;
			this.btnVariantRemove.Text = "Remove";
			this.btnVariantRemove.Click += new System.EventHandler(this.btnVariantRemove_Click);
			// 
			// btnVariantNew
			// 
			this.btnVariantNew.Location = new System.Drawing.Point(448, 16);
			this.btnVariantNew.Name = "btnVariantNew";
			this.btnVariantNew.TabIndex = 2;
			this.btnVariantNew.Text = "New";
			this.btnVariantNew.Click += new System.EventHandler(this.btnVariantNew_Click);
			// 
			// tabPageAssiagnedCategories
			// 
			this.tabPageAssiagnedCategories.Controls.AddRange(new System.Windows.Forms.Control[] {
																									 this.btnRefresh,
																									 this.rdoDirectPricing,
																									 this.rdoUseCategoryPrice,
																									 this.btnClear,
																									 this.btnSet,
																									 this.txtPrimaryCategory,
																									 this.lblPrimaryParent,
																									 this.btnEdit,
																									 this.btnNew,
																									 this.btnAddCategory,
																									 this.btnRemoveCategory,
																									 this.listViewProductCategories,
																									 this.treeViewCategories});
			this.tabPageAssiagnedCategories.Location = new System.Drawing.Point(4, 22);
			this.tabPageAssiagnedCategories.Name = "tabPageAssiagnedCategories";
			this.tabPageAssiagnedCategories.Size = new System.Drawing.Size(672, 294);
			this.tabPageAssiagnedCategories.TabIndex = 2;
			this.tabPageAssiagnedCategories.Text = "Assiagned Categories";
			// 
			// btnRefresh
			// 
			this.btnRefresh.Location = new System.Drawing.Point(8, 256);
			this.btnRefresh.Name = "btnRefresh";
			this.btnRefresh.TabIndex = 12;
			this.btnRefresh.Text = "Refresh";
			this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
			// 
			// rdoDirectPricing
			// 
			this.rdoDirectPricing.Enabled = false;
			this.rdoDirectPricing.Location = new System.Drawing.Point(536, 224);
			this.rdoDirectPricing.Name = "rdoDirectPricing";
			this.rdoDirectPricing.Size = new System.Drawing.Size(136, 24);
			this.rdoDirectPricing.TabIndex = 11;
			this.rdoDirectPricing.Text = "Use Direct Pricing";
			// 
			// rdoUseCategoryPrice
			// 
			this.rdoUseCategoryPrice.Enabled = false;
			this.rdoUseCategoryPrice.Location = new System.Drawing.Point(536, 192);
			this.rdoUseCategoryPrice.Name = "rdoUseCategoryPrice";
			this.rdoUseCategoryPrice.Size = new System.Drawing.Size(136, 24);
			this.rdoUseCategoryPrice.TabIndex = 10;
			this.rdoUseCategoryPrice.Text = "Use Category Pricing";
			// 
			// btnClear
			// 
			this.btnClear.Enabled = false;
			this.btnClear.Location = new System.Drawing.Point(528, 160);
			this.btnClear.Name = "btnClear";
			this.btnClear.TabIndex = 9;
			this.btnClear.Text = "Clear";
			this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
			// 
			// btnSet
			// 
			this.btnSet.Enabled = false;
			this.btnSet.Location = new System.Drawing.Point(528, 128);
			this.btnSet.Name = "btnSet";
			this.btnSet.TabIndex = 8;
			this.btnSet.Text = "Set";
			this.btnSet.Click += new System.EventHandler(this.btnSet_Click);
			// 
			// txtPrimaryCategory
			// 
			this.txtPrimaryCategory.Enabled = false;
			this.txtPrimaryCategory.Location = new System.Drawing.Point(528, 96);
			this.txtPrimaryCategory.Name = "txtPrimaryCategory";
			this.txtPrimaryCategory.Size = new System.Drawing.Size(144, 20);
			this.txtPrimaryCategory.TabIndex = 7;
			this.txtPrimaryCategory.Text = "";
			// 
			// lblPrimaryParent
			// 
			this.lblPrimaryParent.Location = new System.Drawing.Point(528, 72);
			this.lblPrimaryParent.Name = "lblPrimaryParent";
			this.lblPrimaryParent.Size = new System.Drawing.Size(144, 16);
			this.lblPrimaryParent.TabIndex = 6;
			this.lblPrimaryParent.Text = "Primary Parent Category:";
			// 
			// btnEdit
			// 
			this.btnEdit.Enabled = false;
			this.btnEdit.Location = new System.Drawing.Point(528, 40);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.TabIndex = 5;
			this.btnEdit.Text = "Edit";
			this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
			// 
			// btnNew
			// 
			this.btnNew.Location = new System.Drawing.Point(528, 8);
			this.btnNew.Name = "btnNew";
			this.btnNew.TabIndex = 4;
			this.btnNew.Text = "New";
			this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
			// 
			// btnAddCategory
			// 
			this.btnAddCategory.Enabled = false;
			this.btnAddCategory.Location = new System.Drawing.Point(224, 152);
			this.btnAddCategory.Name = "btnAddCategory";
			this.btnAddCategory.Size = new System.Drawing.Size(64, 23);
			this.btnAddCategory.TabIndex = 3;
			this.btnAddCategory.Text = "Add >";
			this.btnAddCategory.Click += new System.EventHandler(this.btnAddCategory_Click);
			// 
			// btnRemoveCategory
			// 
			this.btnRemoveCategory.Enabled = false;
			this.btnRemoveCategory.Location = new System.Drawing.Point(224, 120);
			this.btnRemoveCategory.Name = "btnRemoveCategory";
			this.btnRemoveCategory.Size = new System.Drawing.Size(64, 23);
			this.btnRemoveCategory.TabIndex = 2;
			this.btnRemoveCategory.Text = "< Remove";
			this.btnRemoveCategory.Click += new System.EventHandler(this.btnRemoveCategory_Click);
			// 
			// listViewProductCategories
			// 
			this.listViewProductCategories.Location = new System.Drawing.Point(304, 8);
			this.listViewProductCategories.MultiSelect = false;
			this.listViewProductCategories.Name = "listViewProductCategories";
			this.listViewProductCategories.Size = new System.Drawing.Size(216, 240);
			this.listViewProductCategories.TabIndex = 1;
			this.listViewProductCategories.View = System.Windows.Forms.View.List;
			this.listViewProductCategories.Click += new System.EventHandler(this.listViewProductCategories_Click);
			// 
			// treeViewCategories
			// 
			this.treeViewCategories.ImageList = this.TreeViewimageList;
			this.treeViewCategories.Location = new System.Drawing.Point(8, 8);
			this.treeViewCategories.Name = "treeViewCategories";
			this.treeViewCategories.Size = new System.Drawing.Size(208, 240);
			this.treeViewCategories.TabIndex = 0;
			this.treeViewCategories.Click += new System.EventHandler(this.treeViewCategories_Click);
			this.treeViewCategories.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewCategories_AfterSelect);
			// 
			// TreeViewimageList
			// 
			this.TreeViewimageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
			this.TreeViewimageList.ImageSize = new System.Drawing.Size(16, 16);
			this.TreeViewimageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("TreeViewimageList.ImageStream")));
			this.TreeViewimageList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tabPageRelationShip
			// 
			this.tabPageRelationShip.Controls.AddRange(new System.Windows.Forms.Control[] {
																							  this.dataGridRelationShip,
																							  this.btnRelationShipCancel,
																							  this.btnRelationShipRemove,
																							  this.btnRelationShipEdit,
																							  this.btnRelationShipNew});
			this.tabPageRelationShip.Location = new System.Drawing.Point(4, 22);
			this.tabPageRelationShip.Name = "tabPageRelationShip";
			this.tabPageRelationShip.Size = new System.Drawing.Size(672, 294);
			this.tabPageRelationShip.TabIndex = 3;
			this.tabPageRelationShip.Text = "Product Family RelationShip";
			// 
			// dataGridRelationShip
			// 
			this.dataGridRelationShip.DataMember = "";
			this.dataGridRelationShip.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridRelationShip.Location = new System.Drawing.Point(8, 8);
			this.dataGridRelationShip.Name = "dataGridRelationShip";
			this.dataGridRelationShip.Size = new System.Drawing.Size(664, 240);
			this.dataGridRelationShip.TabIndex = 6;
			// 
			// btnRelationShipCancel
			// 
			this.btnRelationShipCancel.Location = new System.Drawing.Point(424, 256);
			this.btnRelationShipCancel.Name = "btnRelationShipCancel";
			this.btnRelationShipCancel.TabIndex = 5;
			this.btnRelationShipCancel.Text = "Cancel";
			this.btnRelationShipCancel.Click += new System.EventHandler(this.btnRelationShipCancel_Click);
			// 
			// btnRelationShipRemove
			// 
			this.btnRelationShipRemove.Location = new System.Drawing.Point(336, 256);
			this.btnRelationShipRemove.Name = "btnRelationShipRemove";
			this.btnRelationShipRemove.TabIndex = 3;
			this.btnRelationShipRemove.Text = "Remove";
			this.btnRelationShipRemove.Click += new System.EventHandler(this.btnRelationShipRemove_Click);
			// 
			// btnRelationShipEdit
			// 
			this.btnRelationShipEdit.Location = new System.Drawing.Point(248, 256);
			this.btnRelationShipEdit.Name = "btnRelationShipEdit";
			this.btnRelationShipEdit.TabIndex = 2;
			this.btnRelationShipEdit.Text = "Edit";
			this.btnRelationShipEdit.Click += new System.EventHandler(this.btnRelationShipEdit_Click);
			// 
			// btnRelationShipNew
			// 
			this.btnRelationShipNew.Location = new System.Drawing.Point(160, 256);
			this.btnRelationShipNew.Name = "btnRelationShipNew";
			this.btnRelationShipNew.TabIndex = 1;
			this.btnRelationShipNew.Text = "New";
			this.btnRelationShipNew.Click += new System.EventHandler(this.btnRelationShipNew_Click);
			// 
			// tabPageImage
			// 
			this.tabPageImage.Controls.AddRange(new System.Windows.Forms.Control[] {
																					   this.lblImage,
																					   this.pictureBox1});
			this.tabPageImage.Location = new System.Drawing.Point(4, 22);
			this.tabPageImage.Name = "tabPageImage";
			this.tabPageImage.Size = new System.Drawing.Size(672, 294);
			this.tabPageImage.TabIndex = 4;
			this.tabPageImage.Text = "Images";
			// 
			// lblImage
			// 
			this.lblImage.Location = new System.Drawing.Point(16, 16);
			this.lblImage.Name = "lblImage";
			this.lblImage.Size = new System.Drawing.Size(216, 23);
			this.lblImage.TabIndex = 1;
			this.lblImage.Text = "Image:";
			// 
			// pictureBox1
			// 
			this.pictureBox1.Location = new System.Drawing.Point(256, 16);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(416, 264);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			// 
			// panelNavProducts
			// 
			this.panelNavProducts.Controls.AddRange(new System.Windows.Forms.Control[] {
																						   this.btnSave,
																						   this.btnSaveNBack,
																						   this.btnBack});
			this.panelNavProducts.Location = new System.Drawing.Point(0, 320);
			this.panelNavProducts.Name = "panelNavProducts";
			this.panelNavProducts.Size = new System.Drawing.Size(680, 40);
			this.panelNavProducts.TabIndex = 1;
			// 
			// btnSave
			// 
			this.btnSave.Location = new System.Drawing.Point(384, 8);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(96, 23);
			this.btnSave.TabIndex = 2;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnSaveNBack
			// 
			this.btnSaveNBack.Location = new System.Drawing.Point(280, 8);
			this.btnSaveNBack.Name = "btnSaveNBack";
			this.btnSaveNBack.Size = new System.Drawing.Size(96, 23);
			this.btnSaveNBack.TabIndex = 1;
			this.btnSaveNBack.Text = "Save and Back";
			this.btnSaveNBack.Click += new System.EventHandler(this.btnSaveNBack_Click);
			// 
			// btnBack
			// 
			this.btnBack.Location = new System.Drawing.Point(176, 8);
			this.btnBack.Name = "btnBack";
			this.btnBack.Size = new System.Drawing.Size(96, 23);
			this.btnBack.TabIndex = 0;
			this.btnBack.Text = "Back";
			this.btnBack.Click += new System.EventHandler(this.btnBack_Click);
			// 
			// ProductEditor
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(678, 356);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.panelPropertiesProd});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "ProductEditor";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Product Editor";
			this.Load += new System.EventHandler(this.ProductEditor_Load);
			this.panelPropertiesProd.ResumeLayout(false);
			this.tabControlProducts.ResumeLayout(false);
			this.tabPageProductProperties.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGridProductProperties)).EndInit();
			this.tabPageProductVariants.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGridVariants)).EndInit();
			this.tabPageAssiagnedCategories.ResumeLayout(false);
			this.tabPageRelationShip.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGridRelationShip)).EndInit();
			this.tabPageImage.ResumeLayout(false);
			this.panelNavProducts.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private DataSet CreateVerticalDataSet()
		{
			DataSet ds = new DataSet();
			DataTable dt = new DataTable();
			ds.Tables.Add(dt);
			// create two columns DisplayName and Value
			ds.Tables[0].Columns.Add("DisplayName", typeof(string));
			ds.Tables[0].Columns.Add("Value", typeof(string));

			return ds;
		}

		private DataSet MergeVerticaleDataSetToProdcutDataSet(DataTable ProductDataSet)
		{
			// create a vertical dataset
			DataSet ds = CreateVerticalDataSet();
			bool isVariant = false;
			// get the product definition so we can show only what is assigned to the product
			DataTable dtDefinition = ProductProperties.Tables["Definition"];
			// remove the columns we don't want
			foreach(DataRow definiotnRow in dtDefinition.Rows)
			{
				int idx = ProductDataSet.Columns.IndexOf(definiotnRow["PropertyName"].ToString());
				if(idx > 0 && definiotnRow["PropertyType"].ToString()=="0")
				{
					// start binding
					DataRow row = ds.Tables[0].NewRow();
					row["DisplayName"] = definiotnRow["PropertyName"].ToString();
					row["Value"] = ProductDataSet.Rows[0][definiotnRow["PropertyName"].ToString()];
					ds.Tables[0].Rows.Add(row);
				}
				if(definiotnRow["PropertyName"].ToString()=="VariantCode" && definiotnRow["PropertyType"].ToString()=="1")
				{
					isVariant = true;
				}
			}
			// create a new row for product price
			DataRow rowPrice = ds.Tables[0].NewRow();
			// now check to see if we have a variant product
			if(isVariant)
			{
				rowPrice["DisplayName"] = "Default Price";
				rowPrice["Value"] = ProductDataSet.Rows[0]["OriginalPrice"].ToString();
			}
			else
			{
				rowPrice["DisplayName"] = "Price";
				rowPrice["Value"] = ProductDataSet.Rows[0]["cy_List_Price"].ToString();
				// enable the variant tab
				this.tabControlProducts.Controls.Remove(this.tabPageProductVariants);
			}
			ds.Tables[0].Rows.Add(rowPrice);
			return ds;
		}

		private void LoadCategories(DataSet dsCategories)
		{
			foreach(DataRow dr in dsCategories.Tables[0].Rows)
			{
				CategoryNode  cnode = new CategoryNode(dr);
				treeViewCategories.Nodes.Add(cnode);
				treeViewCategories.SelectedImageIndex = 3;
				treeViewCategories.ImageIndex = 3;
			}
		}

		private void LoadCategories(CategoryNode categoryNode, DataSet dsCategories)
		{
			try
			{
				foreach(DataRow dr in dsCategories.Tables[0].Rows)
				{
					// add the data row to each node so we don't have to 
					// go to the server again
					CategoryNode  cnode = new CategoryNode(dr);
					categoryNode.Nodes.Add(cnode);
					categoryNode.SelectedImageIndex = 3;
					categoryNode.ImageIndex = 3;
				}
			}
			catch{}
		}

		private void ProductEditor_Load(object sender, System.EventArgs e)
		{
			// read the xml file and get the file path
			XmlDocument doc = new XmlDocument();
			doc.Load("SiteConfig.xml");
			CSService = new CatalogSystem(doc.FirstChild.InnerText);
			// clear the nodes first
			treeViewCategories.Nodes.Clear();
			// load the catalog tree
			DataSet ds = CSService.GetRootCategories(catalogName);
			LoadCategories(ds);

			// load product data if we don't have a dataset then we are creating a product else we are in edit mode
			if(ProductProperties!=null)
			{
				// looop though all of the tables
				foreach(DataTable dt in ProductProperties.Tables)
				{ 
					// what table are we working with
					switch(dt.TableName)
					{
						case "ProductProperties":
							// do some magic here disable the Display name so we can't change the properties
							DataGridTableStyle dgStyle = new DataGridTableStyle();
							dgStyle.AllowSorting = false;
							dgStyle.MappingName = "Table1";
							DataGridTextBoxColumn DisplayName = new DataGridTextBoxColumn();
							DisplayName.MappingName = "DisplayName";
							DisplayName.HeaderText = "DisplayName";
							DisplayName.Width = 100;
							DisplayName.ReadOnly = true;
							dgStyle.GridColumnStyles.Add(DisplayName);
							// Add a second column style.
							DataGridColumnStyle Value = new DataGridTextBoxColumn();
							Value.MappingName = "Value";
							Value.HeaderText = "Value";
							Value.Width = 150;
							Value.ReadOnly = false;
							dgStyle.GridColumnStyles.Add(Value);
							dataGridProductProperties.TableStyles.Add(dgStyle);
							// disallow new rows from being created
							dataGridProductProperties.DataSource = MergeVerticaleDataSetToProdcutDataSet(dt).Tables[0];
							CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGridProductProperties.DataSource, dataGridProductProperties.DataMember];
							((DataView)cm.List).AllowNew = false;
							break;
						case "Variants":
							// get the variant data
							// clear the datalist and set details
							listViewVariants.Items.Clear();
							listViewVariants.Clear();
							listViewVariants.AllowColumnReorder = true;
							listViewVariants.View = View.Details;

							// Create columns for variants
							DataRow[] drDefinition = ProductProperties.Tables["Definition"].Select("PropertyType='1'");
							foreach(DataRow drDef in drDefinition)
							{
								listViewVariants.Columns.Add(drDef["PropertyName"].ToString(), 100, HorizontalAlignment.Left);
							}
							// create a column for price
							listViewVariants.Columns.Add("Variant Price", 100, HorizontalAlignment.Left);
							// add the data into the list
							string[] lst = new string[listViewVariants.Columns.Count];
							foreach(DataRow dr in dt.Rows)
							{
								// now iterate and get the columns
								for(int i=0;listViewVariants.Columns.Count>i;i++)
								{
									if(listViewVariants.Columns[i].Text=="Variant Price")
									{
										lst[i] = dr["cy_list_price"].ToString();
									}
									else
									{
										lst[i] = dr[listViewVariants.Columns[i].Text].ToString();
									}
								}
								// create our own ProductListView so we can add more info to it
								VariantListView litem = new VariantListView(lst);
								// for some reason litem.dtVaraints.ImportRow(dr) is not working so manully do this
								listViewVariants.Items.Add(litem);
							}
							break;
						case "AssignedCategories":
							// get the assigned categroy data
							// clear the datalist and set details
							listViewProductCategories.Items.Clear();
							listViewProductCategories.Clear();
							listViewProductCategories.AllowColumnReorder = true;
							listViewProductCategories.View = View.Details;

							listViewProductCategories.Columns.Add("Name", 100, HorizontalAlignment.Left);

							foreach(DataRow drCategories in dt.Rows)
							{
								listViewProductCategories.Items.Add(drCategories["Name"].ToString());
							}
							break;
						case "AssignedCategoriesProperties":
							// set additional properties
							//"PricingCategory"
							//"UseCategoryPricing"
							txtPrimaryCategory.Text = dt.Rows[0]["PrimaryParent"].ToString();
							if(dt.Rows[0]["UseCategoryPricing"].ToString()=="False")
							{
								rdoUseCategoryPrice.Checked = false;
								rdoDirectPricing.Checked = true;
							}
							else
							{
								rdoUseCategoryPrice.Checked = true;
							}
							break;
						case "RelatedProducts":
							// get product relationship
							// do some magic here disable the Display name so we can't change the properties
							DataGridTableStyle dgStyleRelatedProducts = new DataGridTableStyle();
							dgStyleRelatedProducts.AllowSorting = false;
							dgStyleRelatedProducts.MappingName = "RelatedProducts";
							DataGridTextBoxColumn TargetCatalog = new DataGridTextBoxColumn();
							TargetCatalog.MappingName = "TargetCatalog";
							TargetCatalog.HeaderText = "TargetCatalog";
							TargetCatalog.Width = 100;
							TargetCatalog.ReadOnly = true;
							dgStyleRelatedProducts.GridColumnStyles.Add(TargetCatalog);
							// Add a second column style.
							DataGridColumnStyle ProductID = new DataGridTextBoxColumn();
							ProductID.MappingName = "ProductID";
							ProductID.HeaderText = "ProductID";
							ProductID.Width = 100;
							ProductID.ReadOnly = true;
							dgStyleRelatedProducts.GridColumnStyles.Add(ProductID);
							// Add a second column style.
							DataGridColumnStyle RelationShipName = new DataGridTextBoxColumn();
							RelationShipName.MappingName = "RelationShipName";
							RelationShipName.HeaderText = "RelationShipName";
							RelationShipName.Width = 150;
							RelationShipName.ReadOnly = false;
							dgStyleRelatedProducts.GridColumnStyles.Add(RelationShipName);
							// Add a second column style.
							DataGridColumnStyle RelationShipDescription = new DataGridTextBoxColumn();
							RelationShipDescription.MappingName = "RelationShipDescription";
							RelationShipDescription.HeaderText = "RelationShipDescription";
							RelationShipDescription.Width = 150;
							RelationShipDescription.ReadOnly = true;
							dgStyleRelatedProducts.GridColumnStyles.Add(RelationShipDescription);
							// Add a second column style.
							DataGridColumnStyle CategoryName = new DataGridTextBoxColumn();
							CategoryName.MappingName = "CategoryName";
							CategoryName.HeaderText = "CategoryName";
							CategoryName.Width = 150;
							CategoryName.ReadOnly = true;
							dgStyleRelatedProducts.GridColumnStyles.Add(CategoryName);
							dataGridRelationShip.TableStyles.Add(dgStyleRelatedProducts);
							// disallow new rows from being created
							dataGridRelationShip.DataSource = dt;
							CurrencyManager cmRelationship = (CurrencyManager)this.BindingContext[dataGridRelationShip.DataSource, dataGridRelationShip.DataMember];
							((DataView)cmRelationship.List).AllowNew = false;
							break;
					}
				}
			}
			else
			{
				// then we are create a new product
				// file the properties with the current definition
				DataSet dsDefintion = CSService.GetDefinitionProperties(this.DefinitionName);
				// create a vertical dataset
				DataSet dsVertical = CreateVerticalDataSet();
				bool isVariant = false;
				// get the product definition so we can show only what is assigned to the product
				DataTable dtDefinition = dsDefintion.Tables[0];
				// remove the columns we don't want
				foreach(DataRow definiotnRow in dtDefinition.Rows)
				{
					//int idx = ProductDataSet.Columns.IndexOf(definiotnRow["PropertyName"].ToString());
					//if(idx > 0 && definiotnRow["PropertyType"].ToString()=="0")
					if(definiotnRow["PropertyType"].ToString()=="0")
					{
						// start binding
						DataRow row = dsVertical.Tables[0].NewRow();
						row["DisplayName"] = definiotnRow["PropertyName"].ToString();
						row["Value"] = null;
						dsVertical.Tables[0].Rows.Add(row);
					}
					if(definiotnRow["PropertyName"].ToString()=="VariantCode" && definiotnRow["PropertyType"].ToString()=="1")
					{
						isVariant = true;
					}
				}
				// create a new row for product price
				DataRow rowPrice = dsVertical.Tables[0].NewRow();
				// now check to see if we have a variant product
				if(isVariant)
				{
					rowPrice["DisplayName"] = "Default Price";
					rowPrice["Value"] = null;
				}
				else
				{
					rowPrice["DisplayName"] = "Price";
					rowPrice["Value"] = null;
					// enable the variant tab
					this.tabControlProducts.Controls.Remove(this.tabPageProductVariants);
				}
				dsVertical.Tables[0].Rows.Add(rowPrice);
				// do some magic here disable the Display name so we can't change the properties
				DataGridTableStyle dgStyle = new DataGridTableStyle();
				dgStyle.AllowSorting = false;
				dgStyle.MappingName = "Table1";
				DataGridTextBoxColumn DisplayName = new DataGridTextBoxColumn();
				DisplayName.MappingName = "DisplayName";
				DisplayName.HeaderText = "DisplayName";
				DisplayName.Width = 100;
				DisplayName.ReadOnly = true;
				dgStyle.GridColumnStyles.Add(DisplayName);
				// Add a second column style.
				DataGridColumnStyle Value = new DataGridTextBoxColumn();
				Value.MappingName = "Value";
				Value.HeaderText = "Value";
				Value.Width = 150;
				Value.ReadOnly = false;
				dgStyle.GridColumnStyles.Add(Value);
				dataGridProductProperties.TableStyles.Add(dgStyle);
				// disallow new rows from being created
				dataGridProductProperties.DataSource = dsVertical.Tables[0];
				CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGridProductProperties.DataSource, dataGridProductProperties.DataMember];
				((DataView)cm.List).AllowNew = false;
			}
		}

		private void listViewVariants_Click(object sender, System.EventArgs e)
		{
			// clear our the grid then get the variant
			lv = (VariantListView)listViewVariants.SelectedItems[0];
			DataSet ds = new DataSet();
			ds.Tables.Add(new DataTable());

			for(int i=0;listViewVariants.Columns.Count>i;i++)
			{
				ds.Tables[0].Columns.Add(listViewVariants.Columns[i].Text, typeof(string));	
			}

			DataRow dr = ds.Tables[0].NewRow();

			for(int i=0;listViewVariants.Columns.Count>i;i++)
			{
				dr[listViewVariants.Columns[i].Text] = lv.SubItems[i].Text;
			}

			ds.Tables[0].Rows.Add(dr);
			dataGridVariants.DataSource = ds.Tables[0];
			CurrencyManager cmVariants = (CurrencyManager)this.BindingContext[dataGridVariants.DataSource, dataGridVariants.DataMember];
			((DataView)cmVariants.List).AllowNew = false;
			NewVariant=false;
		}

		private void treeViewCategories_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			CategoryNode catnode = (CategoryNode)e.Node;

			// check to see if we have child nodes if not then get categories
			CategoryNode nextCatNode = (CategoryNode)catnode.FirstNode;
			if(nextCatNode==null)
			{
				LoadCategories(catnode, CSService.ChildCategories(catnode.CategoryProperty["CatalogName"].ToString(), catnode.Text));
			}
		}

		private void btnSaveNNew_Click(object sender, System.EventArgs e)
		{
			// save the data
			Save();
			// prompt for defenition
			// need to show the definitions avaialble
			ProductForms.ProductDefintion ProdDef = new ProductForms.ProductDefintion();
			ProdDef.ShowDialog(this);
			// reset this form to the new property
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			// save the data
			Save();
		}

		private void btnSaveNBack_Click(object sender, System.EventArgs e)
		{
			// save the data
			Save();
			// close the form
			this.Close();
		}

		private void btnBack_Click(object sender, System.EventArgs e)
		{
			// don't save anything just close the form
			this.Close();
		}

		private void btnRelationShipNew_Click(object sender, System.EventArgs e)
		{
			// show product picker
			ProductForms.ProductPicker ProdPicker = new ProductForms.ProductPicker();
			ProdPicker.ShowDialog();
			// now find out what the user selected
			if(!ProdPicker.isCancel)
			{
				// create the columns to work with
				DataTable dt = ((DataTable)dataGridRelationShip.DataSource);
				if(dt==null)
				{
					dt = new DataTable();
					// if we got a null value then create the columns
					dt.Columns.Add("TragetCatalog", typeof(string));
					dt.Columns.Add("ProductID", typeof(string));
					dt.Columns.Add("RelationShipName", typeof(string));
					dt.Columns.Add("RelationShipDescription", typeof(string));
					dt.Columns.Add("CategoryName", typeof(string));
				}
				// now check to see what we got a category or product
				DataRow objData = ProdPicker.txtSelection.Tag as DataRow;
				if(objData!=null)
				{
					// we got a product so insert the data into the datagrid
					GetRelationRow(dt, objData);
				}
			}
		}

		private void GetRelationRow(DataTable dt, DataRow dr)
		{
			// check to see if we havce a category column
			if(dt.Columns.Count==4)
			{
				dt.Columns.Add("CategoryName", typeof(string));
			}
			// if we got a null value then create the columns
			DataRow RelationRow = null;
			RelationRow = dt.NewRow();
			// make a relation data row
			// check to see if we are using a product
			if(dr["ProductID"].ToString()!="")
			{
				RelationRow["TargetCatalog"]=dr["CatalogName"];
				RelationRow["ProductID"]=dr["ProductID"];
				RelationRow["RelationshipName"]="";
				RelationRow["RelationshipDescription"]="Product";
				RelationRow["CategoryName"]=null;
				dt.Rows.Add(RelationRow);
			}
			else
			{
				RelationRow["TargetCatalog"]=dr["CatalogName"];
				RelationRow["ProductID"]=null;
				RelationRow["RelationshipName"]="";
				RelationRow["RelationshipDescription"]="Category";
				RelationRow["CategoryName"]=dr["CategoryName"];
				dt.Rows.Add(RelationRow);
			}
		}

		private void btnRelationShipEdit_Click(object sender, System.EventArgs e)
		{
			int currentRow = dataGridRelationShip.CurrentRowIndex;
			if(currentRow!=-1)
			{
				// eidt current selection
				// show product picker
				ProductForms.ProductPicker ProdPicker = new ProductForms.ProductPicker();
				ProdPicker.ShowDialog();
				// update the row the user selected for the change
				DataRow objData = ProdPicker.txtSelection.Tag as DataRow;
				if(objData!=null)
				{
					DataRow RelationRow = ((DataTable)dataGridRelationShip.DataSource).Rows[currentRow];
					if(objData["ProductID"].ToString()!="")
					{
						RelationRow["TargetCatalog"]=objData["CatalogName"];
						RelationRow["ProductID"]=objData["ProductID"];
						RelationRow["RelationshipDescription"]="Product";
						RelationRow["CategoryName"]=null;
					}
					else
					{
						RelationRow["TargetCatalog"]=objData["CatalogName"];
						RelationRow["ProductID"]=null;
						RelationRow["RelationshipDescription"]="Category";
						RelationRow["CategoryName"]=objData["CategoryName"];
					}
				}
			}
		}

		private void btnRelationShipRemove_Click(object sender, System.EventArgs e)
		{
			// remove current selection
			int currentRow = dataGridRelationShip.CurrentRowIndex;
			DataRow dr = ((DataTable)dataGridRelationShip.DataSource).Rows[currentRow];
			((DataTable)dataGridRelationShip.DataSource).Rows.Remove(dr);
		}

		private void listViewProductCategories_Click(object sender, System.EventArgs e)
		{
			// enable/disable buttons
			btnRemoveCategory.Enabled = true;
			btnAddCategory.Enabled = false;
			btnEdit.Enabled = true;
			btnSet.Enabled = true;
		}

		private void btnSet_Click(object sender, System.EventArgs e)
		{
			// enable the button
			btnClear.Enabled = true;
			// enable the radio buttons
			rdoUseCategoryPrice.Enabled = true;
			rdoDirectPricing.Enabled = true;
			// move the seletected item to text box
			txtPrimaryCategory.Text = listViewProductCategories.SelectedItems[0].Text;
		}

		private void btnClear_Click(object sender, System.EventArgs e)
		{
			// disable the button
			btnClear.Enabled = false;
			btnSet.Enabled = false;
			// disable the radio buttons
			rdoUseCategoryPrice.Enabled = false;
			rdoDirectPricing.Enabled = false;
			// remove the seletected item from text box
			txtPrimaryCategory.Text = "";
			rdoDirectPricing.Checked = true;
		}

		private void btnRefresh_Click(object sender, System.EventArgs e)
		{
			// clear the nodes first
			treeViewCategories.Nodes.Clear();
			// reload categories
			// load the catalog tree
			DataSet ds = CSService.GetRootCategories(catalogName);
			LoadCategories( ds);
		}

		private void btnRemoveCategory_Click(object sender, System.EventArgs e)
		{
			// ok remove what's selected
			listViewProductCategories.SelectedItems[0].Remove();
			btnRemoveCategory.Enabled = false;
		}

		private void btnAddCategory_Click(object sender, System.EventArgs e)
		{
			// ok add item form the treeview to the list
			// but first check to see if we already have it
			//ListViewItem litem = new ListViewItem(treeViewCategories.SelectedNode.Text);
			bool exists = false;
			foreach(ListViewItem li in listViewProductCategories.Items)
			{
				if(li.Text==treeViewCategories.SelectedNode.Text)
				{
					exists = true;
				}
			}
			if(!exists)
			{
				listViewProductCategories.Items.Add(treeViewCategories.SelectedNode.Text);
			}
			btnAddCategory.Enabled = false;
		}

		private void btnNew_Click(object sender, System.EventArgs e)
		{
			// we need to create a category
			CategoryForms.CategoryEditor cat = new CategoryForms.CategoryEditor();
			cat.ShowDialog(this);
		}

		private void btnEdit_Click(object sender, System.EventArgs e)
		{
			// we need to edit the selected category
			CategoryForms.CategoryEditor cat = new CategoryForms.CategoryEditor();
			cat.ShowDialog(this);
		}

		private void treeViewCategories_Click(object sender, System.EventArgs e)
		{
			// enable/disable buttons
			btnAddCategory.Enabled = true;
			btnRemoveCategory.Enabled = false;
		}

		private void Save()
		{
			// get the product data
			GetProductData();
			// get the Assigned categories
			GetAssignedCategoriesData();
			// check to see if we need variant data
			int idx = this.tabControlProducts.Controls.IndexOf(this.tabPageProductVariants);
			if(idx!=-1)
			{
				// get product variants
				GetVariantData();
			}
			// save the changes
			CSService.SaveProductProperties(this.ProductProperties, this.catalogName);
		}

		private void GetProductData()
		{
			// go through the data grid and match product data
			foreach(DataRow dr in ((DataTable)dataGridProductProperties.DataSource).Rows)
			{
				if(dr["DisplayName"].ToString()=="Default Price")
				{
					ProductProperties.Tables["ProductProperties"].Rows[0]["cy_list_price"]=(object)dr["Value"];
				}
				else if(dr["DisplayName"].ToString()=="Price")
				{
					ProductProperties.Tables["ProductProperties"].Rows[0]["cy_list_price"]=(object)dr["Value"];
				}
				else
				{
					ProductProperties.Tables["ProductProperties"].Rows[0][dr["DisplayName"].ToString()]=(object)dr["Value"];
				}
			}
		}

		private void GetAssignedCategoriesData()
		{
			// make sure we have enough rows
			// get the assigned categroy data
			for(int i=0; listViewProductCategories.Items.Count>i; i++)
			{
				// check to see if we need to add a row
				if(ProductProperties.Tables["AssignedCategories"].Rows.Count<listViewProductCategories.Items.Count)
				{
					DataRow dr = ProductProperties.Tables["AssignedCategories"].NewRow();
					ProductProperties.Tables["AssignedCategories"].Rows.Add(dr);
				}
				ProductProperties.Tables["AssignedCategories"].Rows[i]["Name"]=listViewProductCategories.Items[i].Text;
			}
			// now get parent category
			ProductProperties.Tables["AssignedCategoriesProperties"].Rows[0]["PrimaryParent"] = txtPrimaryCategory.Text;
			// now get pricing

			if(rdoUseCategoryPrice.Checked)
			{
				 ProductProperties.Tables["AssignedCategoriesProperties"].Rows[0]["UseCategoryPricing"]="True";
			}
			else
			{
				ProductProperties.Tables["AssignedCategoriesProperties"].Rows[0]["UseCategoryPricing"]="False";
			}
		}

		private void GetVariantData()
		{
			//Varaint
			// get the variant categroy data
			// make sure we have a datatable for variants
			int iCount = listViewVariants.Items.Count-ProductProperties.Tables["Variants"].Rows.Count;

			// add a new row for each varaint
			for(int k=0; iCount>k; k++)
			{
				//DataRow drVariant = dtVariant.NewRow();
				//dtVariant.Rows.Add(drVariant);
				DataRow drVariant = ProductProperties.Tables["Variants"].NewRow();
				ProductProperties.Tables["Variants"].Rows.Add(drVariant);
			}

			for(int i=0; listViewVariants.Items.Count>i; i++)
			{
				for(int j=0; listViewVariants.Columns.Count>j; j++)
				{
					if(listViewVariants.Columns[j].Text=="Variant Price")
					{
						ProductProperties.Tables["Variants"].Rows[i]["cy_list_price"]=listViewVariants.Items[i].SubItems[j].Text;
					}
					else
					{
						ProductProperties.Tables["Variants"].Rows[i][listViewVariants.Columns[j].Text]=listViewVariants.Items[i].SubItems[j].Text;
					}
				}
			}
		}

		private void btnVariantNew_Click(object sender, System.EventArgs e)
		{
			DataTable dt = new DataTable("Variants");

			for(int i=0;listViewVariants.Columns.Count>i;i++)
			{
				dt.Columns.Add(listViewVariants.Columns[i].Text, typeof(string));
			}

			DataRow dr = dt.NewRow();
			dt.Rows.Add(dr);
			dataGridVariants.DataSource = dr.Table;
			CurrencyManager cmVariants = (CurrencyManager)this.BindingContext[dataGridVariants.DataSource, dataGridVariants.DataMember];
			((DataView)cmVariants.List).AllowNew = false;
			NewVariant = true;
		}

		private void btnVariantRemove_Click(object sender, System.EventArgs e)
		{
			// remove variant
			listViewVariants.Items.Remove(listViewVariants.SelectedItems[0]);
			dataGridVariants.DataSource = null;
		}

		private void btnVariantDone_Click(object sender, System.EventArgs e)
		{
			if(NewVariant)
			{
				lv = new VariantListView();
				// add the data into the list
				string[] lst = new string[listViewVariants.Columns.Count];
				// now iterate and get the columns
				for(int i=0;listViewVariants.Columns.Count>i;i++)
				{
					lst[i] = ((DataTable)dataGridVariants.DataSource).Rows[0][listViewVariants.Columns[i].Text].ToString();
				}
				// create our own ProductListView so we can add more info to it
				VariantListView litem = new VariantListView(lst);
				// for some reason litem.dtVaraints.ImportRow(dr) is not working so manully do this
				listViewVariants.Items.Add(litem);
			}
			else
			{
				// accept the changes and save it to the row
				for(int i=0;listViewVariants.Columns.Count>i;i++)
				{
					lv.SubItems[i].Text = ((DataTable)dataGridVariants.DataSource).Rows[0][listViewVariants.Columns[i].Text].ToString();
				}
			}
			dataGridVariants.DataSource = null;
		}

		private void btnVariantCancel_Click(object sender, System.EventArgs e)
		{
			// undo the changes
			dataGridVariants.DataSource = null;
		}

		private void btnRelationShipAccept_Click(object sender, System.EventArgs e)
		{
			// do validation to make sure all is well
		}

		private void btnRelationShipCancel_Click(object sender, System.EventArgs e)
		{
			// undo
			((DataTable)dataGridRelationShip.DataSource).RejectChanges();
		}
	}
}
